﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Web.Core;
using Web.Core.Objects;

public partial class AdminCP_Articles : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["Language"] == null)
            Session["Language"] = Web.Core.GlobalStorage.Language.Vietnamese;
        int page = 1;
        int pageSize = GlobalStorage.categoriesPerPageForAdmin;
        if (Request.Params["page"] != null)
            page = int.Parse(Request.Params["page"]);

        this.rptArticle.DataSource = Articles.getAllArticle((int)Session["Language"]);
        this.rptArticle.DataBind();

        if (Request.Params["do"] != null)
        {
            string cDo = Request.Params["do"];
            switch (cDo)
            {
                case "edit":
                    if (Request.Params["aid"] != null)
                        LoadControls();
                    break;
                case "add":
                    LoadControls();
                    break;
                case "del":
                    if (Request.Params["aid"] != null)
                    {
                        int artID = 0;
                        try
                        {
                            artID = int.Parse(Request.Params["aid"].ToString());
                        }
                        catch { }
                        //Categories.DeleteCategory(new Category(catID, "", 0, 0, 0));
                        Article temp = new Article();
                        temp.Id = artID;
                        Articles.DeleteArticle(temp);
                        this.PreRenderComplete += new EventHandler(AdminCP_Articles_PreRenderComplete);
                    }
                    break;
                default:
                    break;
            }
        }
    }

    void AdminCP_Articles_PreRenderComplete(object sender, EventArgs e)
    {
        Response.Redirect("Articles.aspx");
    }

    void LoadControls()
    {
        Control addEditCategories = (Control)Page.LoadControl("~/AdminCP/AdminControls/AddEditArticle.ascx");
        this.PlaceHolderBottom.Controls.Add(addEditCategories);
    }
}
